package com.briup.jz.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.jz.bean.Article;
import com.briup.jz.bean.ArticleExample;
import com.briup.jz.bean.Comment;
import com.briup.jz.bean.CommentExample;
import com.briup.jz.bean.extend.CommentExtend;
import com.briup.jz.dao.CommentMapper;
import com.briup.jz.dao.extend.CommentExtendMapper;
import com.briup.jz.service.ICommentService;

//@Service 声明这是一个实现类
@Service
public class CommentServiceimpl implements ICommentService{
	@Autowired
	private CommentMapper commentMapper;
	@Autowired
	private CommentExtendMapper commentExtendMapper;

	@Override
	public List<Comment> findAll() {
		CommentExample example=new CommentExample();
		return commentMapper.selectByExample(example);
	}

	@Override
	public void saveOrUpdate(Comment c1) {
		// TODO Auto-generated method stub
		if(c1.getId()==null) {
			commentMapper.insert(c1);
		}else {
			commentMapper.updateByPrimaryKey(c1);
		}
	}

	@Override
	public Comment findById(Long id) {
		// TODO Auto-generated method stub
		return commentMapper.selectByPrimaryKey(id);
	}

	@Override
	public void delete(Long id) {
		// TODO Auto-generated method stub
		commentMapper.deleteByPrimaryKey(id);
	}

	@Override
	public List<Comment> pageQuery(int page, int pageSize, String keywords) {
		int pageIndex = (page-1)*pageSize;
		return commentExtendMapper.pageQuery(pageIndex, pageSize, keywords);
	}
	


}
